<template>
	<view>
		<view class="mar-15 tform">
			<view class="between center tform-item hang-no">
				<view class="value flex">显示地址</view>
				<view>
					<u-input v-model="form.name" input-align="right" placeholder="请输入功能名称" />
				</view>
			</view>
			<view class="between center tform-item hang-no">
				<view class="value flex">显示编码</view>
				<view>
					<u-input v-model="form.code" input-align="right" placeholder="请输入显示编码" />
				</view>
			</view>
			<view class="between center tform-item hang-no">
				<view class="value flex">功能描述</view>
				<view>
					<u-input v-model="form.describe" input-align="right" placeholder="请输入功能描述" />
				</view>
			</view>
		</view>
		<view class="center">
			<u-button class="btn" type="primary" @click="confirm">提交</u-button>
		</view>
	</view>
</template>

<script>
	import {
		menuAddressAdd,
		menuAddressEdit
	} from '../../api/menuAddress';
	export default {
		props: {
			menuItem: Object
		},
		data() {
			return {
				form: {
					code: "",
					name: "",
					describe: "",
				},
			}
		},
		mounted() {
			this.form = this.menuItem;
		},
		methods: {
			confirm() {
				if (!this.form.name) {
					this.$u.toast('请填写功能名称')
					return;
				}
				if (!this.form.code) {
					this.$u.toast('请填写功能编码')
					return;
				}
				if (this.form.id) {
					menuAddressEdit(this.form).then(res => {
						if (res == 1) {
							this.$emit('close')
						}
					})
				} else {
					menuAddressAdd(this.form).then(res => {
						if (res == 1) {
							this.$emit('close')
						}
					})
				}
				uni.$emit('handleClose')
			}
		}
	}
</script>

<style scoped>

</style>